package cn.wisenergy.pai.monitor.linux.parser;

import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import java.util.Date;

public class Time implements Serializable{
	
	private static final long serialVersionUID = -5769657417414272072L;
	//当前时间
	private long time = 0l;
	//当前时间对应的序列
	private int seq =0;
	
	public long getTime() {
		return time;
	}
	public void setTime(long time) {
		this.time = time;
	}
	public int getSeq() {
		return seq;
	}
	public void setSeq(int seq) {
		this.seq = seq;
	}
	@Override
	public String toString() {
		return "Time [time=" + time + ", seq=" + seq + "]";
	}
	@Override
	public byte[] toBytes() throws IOException{
		ByteArrayOutputStream bytesOutput=new ByteArrayOutputStream();
		DataOutputStream dataOutput=new DataOutputStream(bytesOutput);
		dataOutput.writeInt(seq);
		dataOutput.writeLong(time);
		byte[] result=bytesOutput.toByteArray();
		dataOutput.close();
		bytesOutput.close();
		return result;
	}
	@Override
	public void toObject(byte[] ba) throws IOException {
		ByteArrayInputStream bytesInput=new ByteArrayInputStream(ba);
		DataInputStream dataInput=new DataInputStream(bytesInput);
		if(dataInput.available()>0){
			seq=dataInput.readInt();
		}
		if(dataInput.available()>0){
			time=dataInput.readLong();
		}
		dataInput.close();
		bytesInput.close();
	}
}
